﻿package mortal.game.view.ranking.view
{
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.ranking.util.*;
    import mortal.mvc.core.*;

    public class RankingSearchSpr extends GSprite
    {
        private var _searchInput:GTextInput;
        private var _searchBtn:GLoadingButton;
        private var _careerBox:GComboBox;
        private var _sexBox:GComboBox;
        private var _searchBtn2:GButton;
        private var _resetBtn:GButton;

        public function RankingSearchSpr()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41366), 36, 0, 66, 20, this));
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.LEFT;
            this._searchInput = UIFactory.gTextInput(68 - 2, 0, 127, 23, this);
            this._searchInput.setStyle("textFormat", _loc_1);
            this._searchInput.htmlText = Language.getString(40400);
            this._searchBtn = UIFactory.gLoadingButton(ResFileConst.SearchBtn, 173, 2, 19, 19, this);
            this._careerBox = UIFactory.gComboBox(208 - 10, 0, 85, 23, null, this);
            this._sexBox = UIFactory.gComboBox(436 - 113 - 36, 0, 85, 23, null, this);
            this._searchBtn2 = UIFactory.gButton(Language.getString(41366), 548 - 113 - 53, 0, 43, 20, this);
            this._resetBtn = UIFactory.gButton(Language.getString(41367), 602 - 113 - 59, 0, 43, 20, this);
            this._searchBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._searchInput.configEventListener(FocusEvent.FOCUS_IN, this.onFocusChange);
            this._searchInput.configEventListener(FocusEvent.FOCUS_OUT, this.onFocusChange);
            this._searchBtn2.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._resetBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this.initComboBoxData();
            NetDispatcher.addCmdListener(ServerCommand.GetRoleList, this.onGetSearchRoleHandler);
            return;
        }// end function

        private function initComboBoxData() : void
        {
            this._careerBox.dataProvider = RankingUtil.getComboBoxData(0);
            this._sexBox.dataProvider = RankingUtil.getComboBoxData(2);
            this._careerBox.drawNow();
            this._sexBox.drawNow();
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_3:String = null;
            if (event.target == this._searchBtn)
            {
                _loc_3 = this._searchInput.text;
                if (_loc_3 != "")
                {
                    GameProxy.player.findMiniPlayerByName([_loc_3]);
                }
            }
            var _loc_2:Object = {};
            if (event.target == this._searchBtn2)
            {
                _loc_2["career"] = this._careerBox.selectedItem.career as int;
                _loc_2["camp"] = -1;
                _loc_2["sex"] = this._sexBox.selectedItem.sex as int;
                Dispatcher.dispatchEvent(new DataEvent(EventName.RankingGetListBySearch, _loc_2));
            }
            if (event.target == this._resetBtn)
            {
                this._careerBox.selectedIndex = 0;
                this._sexBox.selectedIndex = 0;
                _loc_2["career"] = this._careerBox.selectedItem.career as int;
                _loc_2["camp"] = -1;
                _loc_2["sex"] = this._sexBox.selectedItem.sex as int;
                Dispatcher.dispatchEvent(new DataEvent(EventName.RankingGetListBySearch, _loc_2));
            }
            return;
        }// end function

        private function onGetSearchRoleHandler(param1:Object) : void
        {
            var _loc_2:* = param1 as Array;
            if (_loc_2.length != 0)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.RankingGetListBySearch, this._searchInput.text));
            }
            else
            {
                MsgManager.showRollTipsMsg(Language.getString(41368));
            }
            return;
        }// end function

        private function onFocusChange(event:FocusEvent) : void
        {
            if (event.type == FocusEvent.FOCUS_IN)
            {
                if (this._searchInput.text == Language.getString(41369))
                {
                    this._searchInput.text = "";
                }
            }
            if (event.type == FocusEvent.FOCUS_OUT)
            {
                if (this._searchInput.text == "")
                {
                    this._searchInput.htmlText = Language.getString(40400);
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._searchBtn.dispose(param1);
            this._searchInput.dispose(param1);
            this._careerBox.dispose(param1);
            this._sexBox.dispose(param1);
            this._searchBtn2.dispose(param1);
            this._resetBtn.dispose(param1);
            this._searchBtn = null;
            this._searchInput = null;
            this._careerBox = null;
            this._sexBox = null;
            this._searchBtn2 = null;
            this._resetBtn = null;
            NetDispatcher.removeCmdListener(ServerCommand.GetRoleList, this.onGetSearchRoleHandler);
            return;
        }// end function

    }
}
